package shuashuami.hb.com.util;

import android.app.Activity;
import android.os.Handler;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;
import android.widget.ListView;

/**
 * Created by Administrator on 2017/7/10.
 */

public class CHallPlatformMenu {
    private Boolean menuIsOpen = false;
    private Animation myAnimation_Translate;
    private LinearLayout llPlatformMenu;
    private ListView getLlPlatformMenu2;
    private LinearLayout llPlatform;
    private Activity activity;

    private Handler mHandler;

    private int mtype=0;


    public void demandWindow(Handler mHan,int type){
        this.mHandler=mHan;
        mtype=type;

    }

    public CHallPlatformMenu(LinearLayout llPlatform, LinearLayout llPlatformMenu, ListView getLlPlatformMenu2, Activity activity) {
        this.llPlatformMenu = llPlatformMenu;
        this.getLlPlatformMenu2 = getLlPlatformMenu2;
        this.activity = activity;
        this.llPlatform = llPlatform;
    }

    public void clickMenu() {
        llPlatform.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mHandler!=null){

                    // 改左边
                    if(mtype==1){
                        mHandler.sendEmptyMessage(0x1);
                    }
                    else if(mtype==2){
                        mHandler.sendEmptyMessage(0x2);
                    }
                    // mHandler.sendEmptyMessage(0x1);

                }
                if (!menuIsOpen) {
                    openMenu();
                } else {
                    closeMenu();
                }
            }
        });
        llPlatformMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                closeMenu();
            }
        });
    }

    public void openMenu() {


        menuIsOpen = true;
        llPlatformMenu.setVisibility(View.VISIBLE);

        myAnimation_Translate = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF, 0,
                Animation.RELATIVE_TO_SELF, 0,
                Animation.RELATIVE_TO_SELF, -1,
                Animation.RELATIVE_TO_SELF, 0);
        myAnimation_Translate.setDuration(200);
        myAnimation_Translate.setInterpolator(AnimationUtils
                .loadInterpolator(activity,
                        android.R.anim.accelerate_decelerate_interpolator));
        getLlPlatformMenu2.startAnimation(myAnimation_Translate);
    }


    public void closeMenu() {
        menuIsOpen = false;
        llPlatformMenu.setVisibility(View.GONE);
    }

}
